<#include '/share.include'>


//package ${basepackage}.controller.admin.${moduleName};
package ${basepackage}.controller.business;
import ${basepackage}.annotation.ExceptionFeedback;
import ${basepackage}.bean.CommonResult;
import ${basepackage}.bean.business.${className};
import ${basepackage}.controller.base.BaseController;
import ${basepackage}.db.domain.PageInfo;
import ${basepackage}.db.domain.PageControl;
import ${basepackage}.log.MISILogger;
import ${basepackage}.log.MISILoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import ${basepackage}.service.${className}Service;

/**
 * ${table.remarks}
 * @author ${author}
 * @date ${.now?datetime}
 */
@Controller
@RequestMapping(value = "/business/${classNameLow}")
public class ${className}Controller extends BaseController {

	private static final MISILogger logger = MISILoggerFactory.getLogger(${className}Controller.class);

    @Autowired
    private ${className}Service ${classNameLow}Service;
	/**
	 * 跳转到列表页面
	 * @param model
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "查询${table.remarks}列表异常")		//定义异常提示消息
	@RequestMapping("/")
	public String index(Model model){
		return getPage(model,1);
		}



	/**
	 * 跳转到指定页面
	 * @param model
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "${table.remarks}列表分页查询异常")		//定义异常提示消息
	@RequestMapping("/page")
	public String getPage(Model model,int page){
		${className} entity = new ${className}();
		<#list columns as column>
		<#if column.columnNameFirstLower='bshangjbId'>
				int sjid = (Integer) getSession().getAttribute(CurrentBusinessID);
				entity.setBshangjbId(sjid);
		</#if>
		</#list>
		PageInfo info = new PageInfo(page>0?page-1:0);
		PageControl<${className}> control = ${classNameLow}Service.page(entity,info,null,null);
		model.addAttribute("page",control);
		return "v1/business/${classNameLow}/list";
	}
	/**
	 * 根据id 查找
	 * @param id
	 * @return son数据
	 */
	@ExceptionFeedback(errorMsg = "根据id查找${table.remarks}异常")		//定义异常提示消息
	@RequestMapping("/get")
	@ResponseBody
	public CommonResult get${className}(@RequestParam(name = "id", required = true)Integer id){
		if (id > 0){
			${className} entity =  ${classNameLow}Service.find(id);
			return CommonResult.successResult(entity);
		}else{
			return CommonResult.exceptionResult("无法解析传入对象！");
		}
	}

	/**
	 * 提交新增请求
	 * @param entity
	 * @param model
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "新增${table.remarks}异常")		//定义异常提示消息
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	@ResponseBody
	public CommonResult add${className}(${className} entity, Model model){
		if (entity!=null){
			int nun=0;
			<#list columns as column>
			<#if column.columnNameFirstLower='bshangjbId'>
			int sjid = (Integer) getSession().getAttribute(CurrentBusinessID);
			entity.setBshangjbId(sjid);
			</#if>
			</#list>
			nun = ${classNameLow}Service.insert${className}(entity);
			if (nun <= 0) {
				return CommonResult.exceptionResult("数据更新失败。");
			}
			return CommonResult.successResult("更新成功！");
		}else {
			return CommonResult.exceptionResult("无法解析传入对象！");
		}
	}
	/**
	 * 提交修改请求
	 * @param entity
	 * @param model
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "修改${table.remarks}异常")		//定义异常提示消息
	@RequestMapping(value = "/edit",method = RequestMethod.POST)
	@ResponseBody
	public CommonResult edit${className}(${className} entity,Model model){
		if (entity!=null){
			int nun = 0;
			nun = ${classNameLow}Service.update${className}(entity);
			if (nun <= 0) {
				return CommonResult.exceptionResult("数据更新失败。");
			}
			return CommonResult.successResult("更新成功！");
		}else {
			return CommonResult.exceptionResult("无法解析传入对象！");
		}
	}
	/**
	 * 根据id删除
	 * @param id
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "删除${table.remarks}异常")		//定义异常提示消息
	@RequestMapping("/del")
	@ResponseBody
	public CommonResult del${className}(@RequestParam(name = "id", required = true)int id){
		int nun = 0;

		nun = ${classNameLow}Service.delete(id);
		if (nun <= 0) {
			return CommonResult.exceptionResult("删除失败。");
		}
		return CommonResult.successResult("删除成功！");
	}

	<#list columns as column>
	<#if column.columnNameFirstLower='youxbz'>
	/**
	 * 根据id作废或恢复，数据库里要存在有效标志。
	 * @param id
	 * @return
	 */
	@ExceptionFeedback(errorMsg = "作废${table.remarks}异常")		//定义异常提示消息
	@RequestMapping("/zouf")
	@ResponseBody
	public CommonResult zuof${className}(@RequestParam(name = "id", required = true)int id,
											@RequestParam(name = "bz", required = true)int bz){
			int nun = 0;

			nun = ${classNameLow}Service.zouf(id,bz);
			if (nun <= 0) {
			return CommonResult.exceptionResult("作废/恢复失败。");
			}
			return CommonResult.successResult("作废/恢复成功！");
			}
</#if>
</#list>

}
